﻿using System;
using System.Collections.Specialized;
class Operate
{
    static void Main(string[] args)
    {
        Graphics g = new Graphics();
        g.setArea(10);
        Console.WriteLine("g的面积为{0}",g.getArea());
        Rectangle r = new Rectangle(4, 5);
        Console.WriteLine("r的面积为{0}", r.getArea());
        Triangle t1 = new Triangle(3,4,5);
        Console.WriteLine("t1的面积为{0}", t1.getArea());
        if (t1.isLegal()) Console.WriteLine("t1合法");
        else Console.WriteLine("t1不合法");

        Console.WriteLine("输入三角形的三条边");
        int a = Convert.ToInt32(Console.ReadLine());
        int b = Convert.ToInt32(Console.ReadLine());
        int c = Convert.ToInt32(Console.ReadLine());
        Triangle t2 = new Triangle(a,b,c);
        if (t2.isLegal())
        {
            Console.WriteLine("该三角形合法");
            Console.WriteLine("该三角形的面积为{0}", t2.getArea());
        }
        else Console.WriteLine("该三角形不合法");


    }


}

class Graphics
{
    protected int area;
    public virtual void setArea(int x)
    {
        area = x;
    }
    virtual public int getArea()
    {
        return area;
    }
}

class Rectangle:Graphics
{
    protected int width;
    protected int height;
    public Rectangle(int w,int h)
    {
        width = w;
        height = h;
    }
    public int getWidth()
    {
        return width;
    }
    public int getHeight()
    {
        return height;
    }
    public override int getArea()
    {
        return width * height;
    }


}
class Triangle : Graphics
{
    protected int len1, len2, len3;
    public Triangle(int len1, int len2, int len3)
    {
        this.len1 = len1;
        this.len2 = len2;
        this.len3 = len3;
    }
    public new double getArea()
    {
        int p = (len1 + len2 + len3) / 2;
        return Math.Sqrt(p * (p - len1) * (p - len2) * (p - len3));
    }
    public bool isLegal()
    {
        return (len1 < len2 + len3) && (len2 < len1 + len3) && (len3 < len1 + len2);
    }
}
   
